package cn.unknownerror.ueteam.team;

import cn.unknownerror.ueteam.data.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * 普通队伍
 */
public class NormalTeam extends AbstractTeam {
    private static final List<NormalTeam> teams = new ArrayList<>();
    private static double exp_share=1;
    private static int radius=0;

    public NormalTeam(String _name, int _maxMember, UUID _captain) throws TeamException {
        super(_name, _maxMember, _captain);
        if(!teams.contains(this)) teams.add(this);
    }
    public NormalTeam(Data data) throws TeamException {
        super(data);
        if(!teams.contains(this)) teams.add(this);
    }
    public NormalTeam(AbstractTeamMeta meta) {
        super(meta);
        if(!teams.contains(this)) teams.add(this);
    }

    @Override
    public boolean equals(Object obj){
        if(!(obj instanceof NormalTeam)){
            return false;
        }
        if(obj == this) {
            return true;
        }
        return ((NormalTeam) obj).getUUID() == this.getUUID();
    }

    public void dissolve() {
        teams.remove(this);
    }

    /**
     * @param _name 查找的关键字
     * @return 如果队伍名字包含了关键字，则会被加入一个List并返回。
     */
    public static List<NormalTeam> searchWithName(String _name){
        List<NormalTeam> result=new ArrayList<NormalTeam>();
        for(NormalTeam t:teams){
            if(t.getName().contains(_name)) result.add(t);
        }
        return result;
    }

    /**
     * @param _uuid 需要获取的队伍的UUID
     * @return 如果找不到，则返回null。如果找到，则返回找到的队伍。
     */
    public static NormalTeam fromUUID(UUID _uuid){
        for(NormalTeam team : teams){
            if(team.getUUID().equals(_uuid)) return team;
        }
        return null;
    }

    /**
     * @return 返回队伍列表的拷贝。
     */
    public static List<NormalTeam> getTeams(){
        return new ArrayList<>(teams);
    }

    public boolean isDissolve(){
        NormalTeam team = fromUUID(getUUID());
        return team == null;
    }

    public static void setExp_share(double _exp_share){
        if(_exp_share>=0&&_exp_share<=1){
            exp_share=_exp_share;
        }
    }

    public static double getExp_share(){
        return exp_share;
    }

    public static int getRadius(){
        return radius;
    }

    public static void setRadius(int _radius){
        if(_radius>=0) radius=_radius;
    }
}
